package com.chl.sort.other;

import java.util.Arrays;
import java.util.Random;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class Sort00Demo {

	static int[] list;
	int[] sortData;

	@BeforeEach
	void init() {
		int count = 10;
		if (count == 10) {
			sortData = new int[] { 0, 1, 2, 7, 9, 3, 4, 5, 6, 8 };
			list = new int[] { 0, 1, 2, 7, 9, 3, 4, 5, 6, 8 };
//			sortData = new int[] { 5, 9, 3, 8, 0, 1, 4, 2, 7, 6 };
//			list = new int[] { 5, 9, 3, 8, 0, 1, 4, 2, 7, 6 };
			return;
		}
//		sortData = new int[] {1,2,3,4,5,6,9,15,16,18,19,7,8,10,11,12,13,14,17,20};
//		list = new int[] {1,2,3,4,5,6,9,15,16,18,19,7,8,10,11,12,13,14,17,20};
		if (list == null) {
			Random r = new Random();
			list = new int[count];
			sortData = new int[count];
			int v;
			for (int i = 0; i < count; i++) {
				v = r.nextInt(1000);
				list[i] = v;
				sortData[i] = v;
			}
		} else {
			sortData = Arrays.copyOf(list, list.length);
		}
	}

	@Test
	void testSelect() {
		Sort02Select.sort(sortData);
	}

	@Test
	void testInsert() {
		Sort03Insert.sort(sortData);
	}

	@Test
	void testBubble() {
		Sort01Bubble.sort(sortData);
	}

	@Test
	void testShell() {
		Sort06Shell.sort(sortData);
	}

	@Test
	void testQuick() {
		Sort04Quick.sort(sortData);
	}
	
	@Test
	void testMerger() {
		Sort05Merger.sort(sortData);
	}
	
	@Test
	void testHeap() {
		Sort07Heap.sort(sortData);
	}

	@AfterEach
	void prints() {
		print(list);
		print(sortData);
	}
	

	static void print(int[] arrs) {
		if (arrs.length <= 1000) {
			for (int i = 0; i < arrs.length; i++) {
				if (i == 0) {
					System.out.print(arrs[i]);
				} else {
					System.out.print("," + arrs[i]);
				}

			}
			System.out.println("\n-----------------");
		}
	}

}
